package com.front.teacher.teacherapp.view.fragment;


import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.front.teacher.teacherapp.R;
import com.front.teacher.teacherapp.base.BaseFragment;
import com.front.teacher.teacherapp.presenter.ActivityPresenter;
import com.front.teacher.teacherapp.view.activity.event.PostThemeActivity;
import com.front.teacher.teacherapp.view.adapter.TabActivityAdapter;
import com.front.teacher.teacherapp.view.impl.IActivityView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 发活动的页面
 */
public class ActivityFragment extends BaseFragment<IActivityView, ActivityPresenter> implements IActivityView {
    public static ActivityFragment activityFragment;
    @InjectView(R.id.image_post_activity)
    ImageView imagePostActivity;
    private TabActivityAdapter tabActivityAdapter;
    private List<Fragment> fragments = new ArrayList<>();

    @InjectView(R.id.tablayout_activity)
    TabLayout tablayoutActivity;
    @InjectView(R.id.viewpager_activity)
    ViewPager viewpagerActivity;

    public static ActivityFragment newInstance() {
        if (activityFragment == null) {
            activityFragment = new ActivityFragment();
        }
        return activityFragment;
    }

    @Override
    public ActivityPresenter initPresenter() {
        return new ActivityPresenter(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_activity;
    }

    @Override
    protected void initData() {
        fragments.add(DummyFragment.newInstance("活动的碎片1"));
        fragments.add(DummyFragment.newInstance("活动的碎片2"));
        fragments.add(DummyFragment.newInstance("活动的碎片3"));
        tabActivityAdapter.notifyDataSetChanged();
    }

    @Override
    protected void initView() {
        tablayoutActivity.setTabMode(TabLayout.MODE_FIXED);
        tabActivityAdapter = new TabActivityAdapter(getFragmentManager(), fragments);
        viewpagerActivity.setAdapter(tabActivityAdapter);
        tablayoutActivity.setupWithViewPager(viewpagerActivity);
        viewpagerActivity.setOffscreenPageLimit(2);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }


    @OnClick(R.id.image_post_activity)
    public void onClick() {
        Intent intent = new Intent(getContext(), PostThemeActivity.class);
        startActivity(intent);
    }
}
